/*     */ package com.controller.front;
/*     */ 
/*     */ import base.dao.BaseExample;
/*     */ import base.dao.BaseExample.Criteria;
/*     */ import base.utils.PageEntity;
/*     */ import base.utils.PagingResult;
/*     */ import base.utils.ResultUtil;
/*     */ import base.utils.StringUtil;
/*     */ import base.utils.UploadFile;
/*     */ import com.model.Accessory;
/*     */ import com.model.Poster;
/*     */ import com.service.AccessoryService;
/*     */ import com.service.PosterService;
/*     */ import java.io.PrintStream;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.ServletContext;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import javax.servlet.http.HttpSession;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.RequestParam;
/*     */ import org.springframework.web.multipart.MultipartFile;
/*     */ import org.springframework.web.multipart.MultipartHttpServletRequest;
/*     */ import org.springframework.web.servlet.ModelAndView;
/*     */ import org.springframework.web.servlet.view.json.MappingJacksonJsonView;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"poster"})
/*     */ public class PosterController
/*     */ {
/*     */   @Autowired
/*     */   private PosterService posterService;
/*     */   @Autowired
/*     */   private AccessoryService accessoryService;
/*     */   
/*     */   @RequestMapping({"uploadp"})
/*     */   public ModelAndView uploadp(HttpServletRequest request, HttpServletResponse response, @RequestParam(value="upload1", required=false) MultipartFile[] excelFile)
/*     */   {
/*  56 */     Map<String, Object> attributes = new HashMap();
/*  57 */     MappingJacksonJsonView view = new MappingJacksonJsonView();
/*  58 */     ModelAndView mv = new ModelAndView();
/*     */     try {
/*  60 */       String user_id = request.getParameter("user_id");
/*  61 */       BaseExample ba = new BaseExample();
/*  62 */       ba.or().andEqualTo("poster_user", user_id);
/*  63 */       List<Map<?, ?>> s = this.posterService.selectByExample(ba);
/*  64 */       Poster p = null;
/*  65 */       if (s.size() == 0) {
/*  66 */         p = new Poster();
/*     */       } else {
/*  68 */         for (Map<?, ?> map : s) {
/*  69 */           int id = ((Integer)map.get("poster_id")).intValue();
/*  70 */           String id1 = id+"";
/*  71 */           p = (Poster)this.posterService.selectByPrimaryKey(id1);
/*     */         }
/*     */       }
/*     */       
/*  75 */       String pic_id = StringUtil.createUUID();
/*  76 */       if ((p.getPoster_accid() != null) && (!"".equals(p.getPoster_accid()))) {
/*  77 */         pic_id = p.getPoster_accid();
/*     */       }
/*  79 */       ServletContext application = request.getSession().getServletContext();
/*  80 */       String excelPath = application.getRealPath("/") + "../accessory/";
/*  81 */       String uploadFileName = "";
/*  82 */       MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest)request;
/*  83 */       MultipartFile file = null;
/*  84 */       Accessory accessory = null;
/*  85 */       if ((excelFile != null) && (excelFile.length > 0) && (excelFile[0].getSize() > 0L)) {
/*  86 */         System.out.println("youdeyoude");
/*     */       }
/*  88 */       int size = excelFile.length;
/*  89 */       System.out.println(excelFile.length);
/*  90 */       for (int i = 0; i < size; i++) {
/*  91 */         file = excelFile[i];
/*  92 */         if ((file != null) && (file.getSize() > 0L))
/*     */         {
/*     */ 
/*  95 */           uploadFileName = UploadFile.uploadFile2(file, excelPath);
/*  96 */           if (!"".equals(uploadFileName)) {
/*  97 */             accessory = new Accessory();
/*  98 */             accessory.setAccessory_id(pic_id);
/*  99 */             accessory.setDeleteFlag(0);
/* 100 */             accessory.setAccessory_name(file.getOriginalFilename());
/* 101 */             accessory.setAccessory_url(uploadFileName);
/* 102 */             accessory.setAddTime(new Date());
/* 103 */             this.accessoryService.insertByEntity(accessory);
/*     */           }
/*     */         }
/*     */       }
/* 107 */       p.setPoster_accid(pic_id);
/* 108 */       p.setPoster_user(Integer.parseInt(user_id));
/*     */       
/* 110 */       if (s.size() == 0) {
/* 111 */         this.posterService.insertByEntity(p);
/*     */       } else {
/* 113 */         this.posterService.updateByEntity(p);
/*     */       }
/* 115 */       attributes.put("code", "0");
/* 116 */       attributes.put("msg", "ok");
/* 117 */       view.setAttributesMap(attributes);
/* 118 */       mv.setView(view);
/* 119 */       return mv;
/*     */     }
/*     */     catch (Exception e) {
/* 122 */       attributes.put("code", "1");
/* 123 */       attributes.put("msg", "系统错误");
/* 124 */       view.setAttributesMap(attributes);
/* 125 */       mv.setView(view); }
/* 126 */     return mv;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   @RequestMapping({"refuse"})
/*     */   public ModelAndView refuse(HttpServletRequest request)
/*     */   {
/* 137 */     ModelAndView mv = new ModelAndView();
/* 138 */     Map<String, Object> attributes = new HashMap();
/* 139 */     MappingJacksonJsonView view = new MappingJacksonJsonView();
/*     */     try
/*     */     {
/* 142 */       String message = new String(request.getParameter("message").getBytes("ISO-8859-1"), "utf-8");
/* 143 */       String acc_id = request.getParameter("acc_id");
/* 144 */       if (("".equals(acc_id)) || (acc_id == null)) {
/* 145 */         Map<String, Object> map = new HashMap();
/* 146 */         return ResultUtil.returnJsonStr("1", "acc_id参数为空", attributes, map, view, mv);
/*     */       }
/* 148 */       if (("".equals(message)) || (message == null)) {
/* 149 */         Map<String, Object> map = new HashMap();
/* 150 */         return ResultUtil.returnJsonStr("1", "message参数为空", attributes, map, view, mv);
/*     */       }
/*     */       
/* 153 */       Accessory acc = (Accessory)this.accessoryService.selectByPrimaryKey(acc_id);
/* 154 */       acc.setAccessory_zt("2");
/* 155 */       acc.setAccessory_con(message);
/* 156 */       this.accessoryService.updateByEntity(acc);
/* 157 */       Map<String, Object> map = new HashMap();
/* 158 */       return ResultUtil.returnJsonStr("0", "ok", attributes, map, view, mv);
/*     */     } catch (Exception e) {
/* 160 */       e.printStackTrace();
/* 161 */       Map<String, Object> map = new HashMap();
/* 162 */       return ResultUtil.returnJsonStr("1", "系统错误", attributes, map, view, mv);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   @RequestMapping({"pass"})
/*     */   public ModelAndView pass(HttpServletRequest request)
/*     */   {
/* 173 */     ModelAndView mv = new ModelAndView();
/* 174 */     Map<String, Object> attributes = new HashMap();
/* 175 */     MappingJacksonJsonView view = new MappingJacksonJsonView();
/*     */     try {
/* 177 */       String acc_id = request.getParameter("acc_id");
/* 178 */       if (("".equals(acc_id)) || (acc_id == null)) {
/* 179 */         Map<String, Object> map = new HashMap();
/* 180 */         return ResultUtil.returnJsonStr("1", "acc_id参数为空", attributes, map, view, mv);
/*     */       }
/*     */       
/* 183 */       Accessory acc = (Accessory)this.accessoryService.selectByPrimaryKey(acc_id);
/* 184 */       acc.setAccessory_zt("3");
/* 185 */       this.accessoryService.updateByEntity(acc);
/* 186 */       Map<String, Object> map = new HashMap();
/* 187 */       return ResultUtil.returnJsonStr("0", "ok", attributes, map, view, mv);
/*     */     } catch (Exception e) {
/* 189 */       e.printStackTrace();
/* 190 */       Map<String, Object> map = new HashMap();
/* 191 */       return ResultUtil.returnJsonStr("1", "系统错误", attributes, map, view, mv);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   @RequestMapping({"getPosterList"})
/*     */   public ModelAndView getPosterList(HttpServletRequest request)
/*     */   {
/* 203 */     ModelAndView mv = new ModelAndView();
/* 204 */     Map<String, Object> attributes = new HashMap();
/* 205 */     MappingJacksonJsonView view = new MappingJacksonJsonView();
/* 206 */     String page = (request.getParameter("page") == null) || ("".equals(request.getParameter("page"))) ? "1" : request.getParameter("page");
/* 207 */     String size = (request.getParameter("size") == null) || ("".equals(request.getParameter("size"))) ? "20" : request.getParameter("size");
/*     */     try
/*     */     {
/* 210 */       String user_id = request.getParameter("user_id");
/* 211 */       BaseExample be = new BaseExample();
/* 212 */       be.or().andEqualTo("deleteFlag", Integer.valueOf(0)).andEqualTo("poster_user", user_id);
/* 213 */       PageEntity pe = new PageEntity();
/* 214 */       pe.setPage(Integer.valueOf(Integer.parseInt(page)));
/* 215 */       pe.setSize(Integer.valueOf(Integer.parseInt(size)));
/* 216 */       pe.setParams(be);
/* 217 */       PagingResult pr = this.posterService.selectPagination(pe);
/* 218 */       System.out.println(pr.getResultList());
/* 219 */       List<Map<?, ?>> list = pr.getResultList();
/*     */       
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 226 */       String accid = ((Map)list.get(0)).get("poster_accid").toString();
/*     */       
/*     */ 
/* 229 */       mv.addObject("fjlist", fjList(accid));
/* 230 */       mv.setViewName("/uploadp.jsp");
/*     */     }
/*     */     catch (Exception e) {
/* 233 */       e.printStackTrace();
/*     */     }
/*     */     
/*     */ 
/* 237 */     return mv;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   @RequestMapping({"getposterList"})
/*     */   public ModelAndView getposterList(HttpServletRequest request)
/*     */   {
/* 246 */     ModelAndView mv = new ModelAndView();
/* 247 */     Map<String, Object> attributes = new HashMap();
/* 248 */     MappingJacksonJsonView view = new MappingJacksonJsonView();
/*     */     try
/*     */     {
/* 251 */       String user_id = request.getParameter("user_id");
/*     */       
/* 253 */       BaseExample ba = new BaseExample();
/* 254 */       ba.or().andEqualTo("poster_user", user_id);
/* 255 */       ba.leftJoinOn("Accessory", "Accessory_id", "poster_accid");
/* 256 */       ba.or(0).andEqualTo("Accessory", "DeleteFlag", "0");
/* 257 */       ba.or(0).andEqualTo("deleteFlag", "0");
/* 258 */       ba.setOrderByClause("Accessory.addTime DESC");
/* 259 */       List<Map<?, ?>> l = this.posterService.selectByExample(ba);
/* 260 */       if (l.size() == 0) {
/* 261 */         List<Map<?, ?>> m = new ArrayList();
/* 262 */         Object o = null;
/* 263 */         attributes.put("code", "0");
/* 264 */         attributes.put("msg", "ok");
/* 265 */         attributes.put("date", o);
/* 266 */         view.setAttributesMap(attributes);
/* 267 */         mv.setView(view);
/* 268 */         return mv;
/*     */       }
/* 270 */       Map<?, ?> m = (Map)l.get(0);
/*     */       
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 276 */       attributes.put("code", "0");
/* 277 */       attributes.put("msg", "ok");
/* 278 */       attributes.put("date", m);
/* 279 */       view.setAttributesMap(attributes);
/* 280 */       mv.setView(view);
/* 281 */       return mv;
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 285 */       e.printStackTrace();
/*     */       
/*     */ 
/* 288 */       attributes.put("code", "1");
/* 289 */       attributes.put("msg", "系统错误");
/* 290 */       view.setAttributesMap(attributes);
/* 291 */       mv.setView(view); }
/* 292 */     return mv;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private List<Map<?, ?>> fjList(String id)
/*     */   {
/* 303 */     BaseExample ba = new BaseExample();
/* 304 */     ba.or().andEqualTo("Accessory_id", id).andEqualTo("DeleteFlag", Integer.valueOf(0));
/* 305 */     List<Map<?, ?>> list1 = this.accessoryService.selectByExample(ba);
/*     */     
/* 307 */     return list1;
/*     */   }
/*     */   
/*     */   @RequestMapping({"fjDel"})
/*     */   public ModelAndView fjDel(HttpServletRequest request) {
/* 312 */     ModelAndView mv = new ModelAndView();
/* 313 */     Map<String, Object> attributes = new HashMap();
/* 314 */     MappingJacksonJsonView view = new MappingJacksonJsonView();
/*     */     try {
/* 316 */       String fjid = request.getParameter("fjid");
/* 317 */       Accessory accessory = (Accessory)this.accessoryService.selectByPrimaryKey(fjid);
/* 318 */       accessory.setDeleteFlag(1);
/* 319 */       this.accessoryService.updateByEntity(accessory);
/* 320 */       Map<String, Object> map = new HashMap();
/* 321 */       return ResultUtil.returnJsonStr("0", "ok", attributes, map, view, mv);
/*     */     }
/*     */     catch (Exception e) {
/* 324 */       e.printStackTrace();
/* 325 */       Map<String, Object> map = new HashMap();
/* 326 */       return ResultUtil.returnJsonStr("1", "系统错误", attributes, map, view, mv);
/*     */     }
/*     */   }
/*     */   
/*     */   @RequestMapping({"jump"})
/*     */   public ModelAndView jump(HttpServletRequest request)
/*     */   {
/* 333 */     ModelAndView mv = new ModelAndView();
/* 334 */     mv.setViewName("/uploadp.jsp");
/* 335 */     return mv;
/*     */   }
/*     */ }


/* Location:              C:\Users\chengkp\Desktop\interwar\WEB-INF\classes\!\com\controller\front\PosterController.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */